package cn.wolfcode.mycat.service;

import cn.wolfcode.mycat.domain.ReceiveErpRecordEntity;
import cn.wolfcode.mycat.util.IdKeyGeneratorUtils;
import com.godbean.wuji.commons.db.elasticsearch.ElasticsearchClient;
import com.godbean.wuji.commons.db.elasticsearch.EsEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: Jason
 * @Date: 2021/03/23/21:11
 * @Description: receive_erp_record索引
 */
@Service
@Slf4j
public class ElasticsearchReceiveErpRecordService {
	
	private static final String indexName = "receive_erp_record_index";
	
	@Resource
	private ElasticsearchClient elasticsearchClient;
	
	public String save(ReceiveErpRecordEntity receiveErpRecordEntity) {
		//雪花算法生成id
		long id = IdKeyGeneratorUtils.nextId();
		EsEntity esEntity = new EsEntity();
		esEntity.setId(id + "");
		receiveErpRecordEntity.setId(id);
		esEntity.setData(receiveErpRecordEntity);
		return elasticsearchClient.addData(indexName, esEntity);
	}
}
